<script>
// start
// promise2
// end
// promise3
// promise4
// settimeout
// promise1
// setTimeout2


    console.log('start');

    setTimeout(() => { //加入到宏任務隊列 1
        console.log('settimeout');

        Promise.resolve()
            .then(() => { //微任务队列 4
                console.log('promise1');

            })
    }, 0)

    new Promise((resolve, reject) => { //new Promise是同步代碼
        console.log('promise2');
        resolve()
    })
        .then(() => {//加到微任務隊列1
            console.log('promise3');
            setTimeout(()=>{ //加到宏任务队列 2 
                console.log('setTimeout2');
                
            },0)
        })
        .then(() => {//微任务队列 2
            Promise.resolve()
                .then(() => {//微任务队列3
                    console.log('promise4');
                    
                })
        })

    console.log('end');
    // start  end  promise2  promise3  settimeout2  promise4  settimeout  promise1

</script>